package com.zs.juc;

/**
 * 说说下⾯这道题的结果？
 *
 * @author madison
 * @description
 * @date 2021/5/28 20:08
 */
public class VolatileTest {
    private static volatile int race = 0;

    public static void increase() {
        race++;
    }

    private static final int THREAD_COUNT = 10;

    public static void main(String[] args) {
        Thread[] threads = new Thread[THREAD_COUNT];
        for (int i = 0; i < THREAD_COUNT; i++) {
            threads[i] = new Thread(() -> {
                for (int j = 0; j < 10000; j++) {
                    increase();
                }
            });
            threads[i].start();
        }

        System.out.println(Thread.activeCount());
        Thread.currentThread().getThreadGroup().list();
//        while (Thread.activeCount() > 1) {
//            Thread.yield();
//        }
        System.out.println(race);
    }
}
